package com.chenglu.android.store;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chenglu.android.R;
import com.chenglu.android.common.base.BaseActionBarActivity;
import com.chenglu.android.common.utils.GlideUtils;
import com.chenglu.android.goodsinfo.bean.ShopsinfoBean;
import com.chenglu.android.goodsinfo.touch.BigImgActivity;
import com.chenglu.android.index.bean.IndexRecomBean;
import com.chenglu.android.store.adapter.StoreDesAdapter;
import com.chenglu.android.store.bean.ChartBangBean;
import com.chenglu.android.store.mvp.contract.StoreContract;
import com.chenglu.android.store.mvp.presenter.StorePresenter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author: lyj
 * @Created: by Copyright 2023/10/25 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：
 */
public class StoreInfoActivity extends BaseActionBarActivity<StorePresenter> implements StoreContract.View {


    @BindView(R.id.iv_shop_header)
    ImageView ivShopHeader;
    @BindView(R.id.cv_user)
    CardView cvUser;
    @BindView(R.id.tv_shopname)
    TextView tvShopname;
    @BindView(R.id.ratingBar_service)
    RatingBar ratingBarService;
    @BindView(R.id.rt_shop_des)
    RelativeLayout rtShopDes;
    @BindView(R.id.rv_service_des)
    RecyclerView rvServiceDes;
    @BindView(R.id.tv_store_des)
    TextView tvStoreDes;
    @BindView(R.id.iv_business_img)
    ImageView ivBusinessImg;
    private StoreDesAdapter storeDesAdapter;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_store_info;
    }

    @Override
    protected void initView() {
        setCenterText("店铺详情");

        mPresenter = new StorePresenter();
        mPresenter.attachView(this);
        String tenandId = getIntent().getStringExtra("tenandId");

        initAdapter();

        mPresenter.getShopinfo(tenandId);

    }

    List<ShopsinfoBean.Data.ServicesList> list = new ArrayList<>();

    private void initAdapter() {
        storeDesAdapter = new StoreDesAdapter(mContext, list);
        rvServiceDes.setLayoutManager(new LinearLayoutManager(this));
        rvServiceDes.setAdapter(storeDesAdapter);
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
    List<String> images = new ArrayList<>();
    @Override
    public void getShopinfo(ShopsinfoBean bean) {

        tvShopname.setText(bean.getData().getShopsName());
        ratingBarService.setRating(bean.getData().getScore());
//        ratingBarService.setNumStars(bean.getData().getScore());
        GlideUtils.setImageView(mContext, bean.getData().getLogoImage(), ivShopHeader);

        if (bean.getData().getServicesList().size() > 0) {
            rvServiceDes.setVisibility(View.VISIBLE);
            for (int i = 0; i < bean.getData().getServicesList().size(); i++) {
                list.add(bean.getData().getServicesList().get(i));

            }
            storeDesAdapter.notifyDataSetChanged();

        } else {
            rvServiceDes.setVisibility(View.GONE);
        }
        if(!TextUtils.isEmpty(bean.getData().getBusinessLicenseImg())){
            images.add(bean.getData().getBusinessLicenseImg());
            RequestOptions options = new RequestOptions()
                    .placeholder(R.color.color_f6f6f6)
                    .error(R.color.color_f6f6f6);
            //设置最大的图片加载宽度
            Glide.with(mContext).load(bean.getData().getBusinessLicenseImg())
                    .override(1080, 2240)
                    .fitCenter()
                    .apply(options)
                    .into(ivBusinessImg);
        }

        tvStoreDes.setText(bean.getData().getDescriptions());

    }

    @Override
    public void getShopsTypes(ChartBangBean bean) {

    }

    @Override
    public void getLikeLists(IndexRecomBean bean) {

    }

    @Override
    public void getSearchGoods(IndexRecomBean bean) {

    }

    @Override
    public void getShopsRecommendPage(IndexRecomBean bean) {

    }

    @OnClick(R.id.iv_business_img)
    public void onViewClicked() {

        Intent intent = new Intent(mContext, BigImgActivity.class);
        intent.putStringArrayListExtra("imgData", (ArrayList<String>) images);
        intent.putExtra("clickPosition", 0);
        startActivity(intent);
    }
}
